From bbf891bcd1841bc61d0726d11988b8c9bf8d6757 Mon Sep 17 00:00:00 2001 From: Matthew Daley Date: Wed, 30 Oct 2013 20:51:42 +1300 Subject: [PATCH] libxc: don't read uninitialized size value in xc_read_image This error case can only be triggered by gzread returning 0 (and having not read anything), so move it there. Coverity-ID: 1056076 Signed-off-by: Matthew Daley Reviewed-by: Andrew Cooper Acked-by: Ian Campbell --- tools/libxc/xg_private.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/libxc/xg_private.c b/tools/libxc/xg_private.c index 8fa068ef43..a914068fc3 100644 --- a/tools/libxc/xg_private.c +++ b/tools/libxc/xg_private.c @@ -71,6 +71,12 @@ char *xc_read_image(xc_interface *xch, image = NULL; goto out; case 0: /* EOF */ + if ( *size == 0 ) + { + PERROR("Could not read kernel image"); + free(image); + image = NULL; + } goto out; default: *size += bytes; @@ -80,13 +86,7 @@ char *xc_read_image(xc_interface *xch, #undef CHUNK out: - if ( *size == 0 ) - { - PERROR("Could not read kernel image"); - free(image); - image = NULL; - } - else if ( image ) + if ( image ) { /* Shrink allocation to fit image. */ tmp = realloc(image, *size); -- 2.30.2